package com.md.api.controller;

import com.md.api.annotation.NoRepeatSubmit;
import com.md.api.entity.HttpResult;
import com.md.api.entity.RechargeOrder;
import com.md.api.service.RechargeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@RequestMapping("/pay")
@RestController
public class RechargeController {


	@Resource
    RechargeService payService;



	//充值
	@NoRepeatSubmit
	@RequestMapping("/recharge")
	public HttpResult recharge(HttpServletRequest request, @RequestBody RechargeOrder order) {
		if (null==order.getActualPay()||null==order.getTotalMoney()){
			return HttpResult.PARAM_ERROR;
		}
		return payService.recharge(request,order);
	}

	@RequestMapping("/rechargeNotify")
	public String rechargeNotify(HttpServletRequest request,HttpServletResponse response) throws IOException {
		return payService.rechargeNotify(request);
	}
}
